*******************************************************************************
* The political of Chinese debt and IMF conditionality (GSQ-2022-020)
*******************************************************************************

* Data and variables
*******************************************************************************
  
  use "GSQ replication", clear 
  
  g lntot=ln(0.1+tot_gdp)
  
  g crd_tot=crd_prv+crd_gov
  g lncrdtot=ln(crd_tot)
  g lncrdprv=ln(crd_prv)
  
  g imfiv=imfav*lnliq

  global M0  l.mlnpop l.mlngdppc l.mser_gdp l.mkoffigidj l.ms_unga3g7 
  global M1  $M0 l.mv2x_corr l.mnatres 
  global M2  $M1 l.mlncredtot l.mlncrdprv
  
  global N0  l.lnpop l.lngdppc l.ser_gdp l.KOFFiGIdj l.s_unga3g7 
  global N1  $N0 l.v2x_corr l.natresource_rents_WDI
  global N2  $N1 l.lncrdtot l.lncrdprv 

  
* Descriptive plots 
*******************************************************************************  
  
* Figure 1: Evolution of China debt

  graph box chinadebt_gdp if sample==1, over(year, label(angle(90))) scheme(s1mono) ytitle("China loans (% GDP)")
  graph export "Figure 1.png", replace width(1200)
  
* Figure 2: Selected countries and China debt 
  
  preserve
	egen maxdebt=max(chinadebt), by(cid)
	g plot=maxdebt>20
	tab plot 
	drop if plot==0 | sample==0
	twoway connected chinadebt_gdp year if plot==1 & sample==1 & chinadebt!=., by(iso3, note(" ")) legend(off) scheme(s1mono) ytitle("China debt (% GDP)") xtitle(" ") note(" ")
	graph export "Figure 2.png", width(1200) replace
  restore


* Main results
*******************************************************************************  

* Table 1: China loan default, domestic crisis, and IMF programs.

  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1, a(cid year) vce(cl cid)
  est store a11
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M1 ms5 if sample==1, a(cid year) vce(cl cid)
  est store a12
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M2 ms5 if sample==1, a(cid year) vce(cl cid)
  est store a13 
  estout a1*, drop(_* *0*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3)) 

  
* Figure 3: Marginal effect of China loan default on IMF program at different values of the crisis index.

  qui g INTER=F1*defchn 
  qui reg IMFnn ms5 defchn F1 INTER $M0 i.year i.cid if sample==1, cl(cid)
  grinter defchn, const(F1) inter(INTER) scheme(s1mono) clevel(95) kdens 
  addplot: hist F1 if sample==1, freq yaxis(2) yscale(alt axis(2)) below width(1) legend(off) fcolor(none) lpattern(" -") lwidth(0.2) lcolor(gs9)
  drop INTER 
  
  g LFDEF=l.F1*l.defchn
  g LF=l.F1
  g LDEF=L.defchn 
  qui reg IMFnn LF LDEF LFDEF ms5 l.defany $M0 i.cid if sample==1, ro cl(cid)
  margins, at(LDEF=(0 1) LF=0 LFDEF=0) vce(uncond)
  margins, at(LDEF=(0 1) LF=0.956 LFDEF=(0 0.956)) vce(uncond)
  drop LDEF LF LFDEF 
  ** 2SD increase in F given LDEF=1 -- from 36% to 63% **

  
* Table 2: Including interaction of crisis and other default
  
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany##cl.F1 $M0 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r01
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany##cl.F1 $M1 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r02
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany##cl.F1 $M2 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r03 
  estout r0*, drop(_* *0* oL.*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3)) 
  
  
* Table 3: Scope conditions.

  ** Corruption 
  su v2x_corr if sample, d 
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1 & v2x_corr>0.63, a(cid year) vce(cl cid)
  est store b11
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1 & v2x_corr<=0.63, a(cid year) vce(cl cid)
  est store b12
  
  ** Fuel resources 
  su ex_fuel if sample, d
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1 & ex_fuel>3.65, a(cid year) vce(cl cid)
  est store b21
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1 & ex_fuel<=3.65, a(cid year) vce(cl cid)
  est store b22
    
  ** Autocracy 
  su p_ipolity if sample, d
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1 & p_ipolity<6, a(cid year) vce(cl cid)
  est store b31
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $M0 ms5 if sample==1 & p_ipolity>=6, a(cid year) vce(cl cid)
  est store b32
  estout b1* b2* b3*, drop(_* *0* ) starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(N N_clust r2, fmt(0 0 3)) 
  
  
* Table 4: China loans, other loans, and IMF conditionality.  

  qui reghdfe BA2TOT l.lnchina l.lntot $M0 ms5 if sample==1 & IMFnn==1, a(cid year) vce(cl cid)
  est store c11
  qui reghdfe BA2TOT l.lnchina l.lntot $M1 ms5 if sample==1 & IMFnn==1, a(cid year) vce(cl cid)
  est store c12
  qui reghdfe BA2TOT l.lnchina l.lntot $M2 ms5 if sample==1 & IMFnn==1, a(cid year) vce(cl cid)
  est store c13
  estout c1*, drop(_* ) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N N_clust r2, fmt(0 0 3)) 
  
  qui reg BA2TOT l.lnchina l.lntot l.lnpop l.lngdppc l.ser_gdp l.KOFFiGIdj l.s_unga3g7 i.year i.cid if sample==1 & IMFnn==1
  su l.lnchina l.KOFFiGIdj if e(sample)
  margins, at(l.lnchina=(-0.64 1.08))
  margins, at(l.KOFFiGIdj=(46.40 61.23))
  predict yhat, xb 
  edit iso3 year yhat BA2TOT lnchina lntot lnpop lngdppc ser_gdp KOFFiGIdj s_unga3 if IMFnn==1
  margins, at(l.lnchina=-0.446 l.lntot=1.965 l.lnpop=16.3 l.lngdppc=7.07 l.ser_gdp=47.5 l.KOFFiGIdj=74 l.s_unga3=-2.1)
   ** predicts 15.3522 **
  margins, at(l.lnchina=0.886 l.lntot=1.965 l.lnpop=16.3 l.lngdppc=7.07 l.ser_gdp=47.5 l.KOFFiGIdj=74 l.s_unga3=-2.1)
   ** predicts 17.18 **

   
* Appendix
*******************************************************************************  

* Table A1 

  egen defoff=rowtotal(def_paris def_oth)
  replace defoff=defoff>0
  
  egen defprv=rowtotal(def_othpr def_fcbk)
  replace defprv=defprv>0
  
  edit iso3 year IMFnn defchn defany defoff defprv if sample==1


* Table A3: Correlation matrix

  corr defchn F1 defany lnpop lngdppc ser_gdp KOFFiGI s_unga3 v2x_corr   
  
  
* Table A4: Variable definitions and descriptive statistics

  qui estpost su IMFnn BA2TOT lnchina lntot defchn defany F1 $X capform pcons rtfp hf_financ lninrs npl lnliq chn_steel res_chn fchnswap wbsal RFAInd if sample==1 
  esttab ., cells("count mean sd min max")  

  
* Table A5: China loan default, domestic crisis, and IMF programs with unimputed controls.

  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $N0 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r11
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $N1 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r12
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany $N2 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r13 
  estout r1*, drop(_* *0*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 


* Table A6: Access to alternative sources of finance 

  replace cn_fgiv=0 if cn_fgiv==.
  replace cn_dresc=0 if cn_dresc==.
  replace cn_dreneg=0 if cn_dreneg==.
  replace fchnswap=0 if fchnswap==.
  egen cn_any=rowmax(cn_fgiv cn_dresc cn_dreneg)
  
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany l.cn_any l.fchnsw l.wbsal l.RFAInd $M0 ms5 if sample==1, a(cid year) vce(cl cid)
  est store r21
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany l.cn_any l.fchnsw l.wbsal l.RFAInd ms5 $M1 if sample==1, a(cid year) vce(cl cid)
  est store r22
  qui reghdfe IMFnn l.defchn##cl.F1 l.defany l.cn_any l.fchnsw l.wbsal l.RFAInd ms5 $M2 if sample==1, a(cid year) vce(cl cid)
  est store r23
  estout r2*, drop(_* *0*) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2_a, fmt(0 3)) 


* Table A7: Determinants of Chinese loan default.

  qui reghdfe defchn l.defany l.IMFnn $M0 if l.chn_gdp>0 & sample==1, a(cid year) vce(cl cid)
  est store r31
  qui reghdfe defchn l.defany l.IMFnn $M1 if l.chn_gdp>0 & sample==1, a(cid year) vce(cl cid)
  est store r32
  qui reghdfe defchn l.defany l.IMFnn $M2 if l.chn_gdp>0 & sample==1, a(cid year) vce(cl cid)
  est store r33
  estout r3*, drop(_* ) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2, fmt(0 3)) 
  
  
* Table A8: Covariate balances tables for defaulters to different creditors.

  preserve
 
  drop if sample==0
  collapse (mean)chinadebt_gdp defany defoff defchn (mean)IMFnn BA2TOT IMFon wbsal (mean)lntot infl wdi_gdpcapcon2010 wdi_gdppppcur KOFPoGI KOFFiGI peg growth_WDI p_ipolity fh_inv v2x_corr_VDEM sfi_SFI presany_DPI leftany_DPI exelec legelec s_unga3g7 coupi civwar_UCDP banks3 eventsNat natres  lnpop F1, by(iso3)

  g treat0=IMFnn>0
  g treat3=(chinadebt_gdp>3)
  g lngdp=ln(wdi_gdpppp)
  g lngdppc=ln(wdi_gdpcap)
  
  su defchn, d
  g treat1=defchn>0
  replace treat1=. if defchn==.
  su defoff, d
  g treat2=defoff>0.724 
  
  g treat=.
  replace treat=1 if treat1==1
  replace treat=0 if treat2==1
  replace treat=. if treat1==1 & treat2==1
  balancetable treat IMFnn BA2TOT lngdppc lngdp lntot infl growth natres eventsNat KOFFiGI p_ipolity presany leftany sfi KOFPoGI coupi banks3 civwar_UCDP v2x_corr_VDEM unsc_DSV s_unga using "Table A9.xlsx", replace wide(mean1 mean2 diff se)
  
  restore 

  
* Table A9: Covariate balance tables for borrowers from different creditors. 

  preserve 
  
  drop if sample==0 & (chinadebt==0 | chinadebt==.)
  
  collapse (mean)chinadebt_gdp chn_gdp defany defoff defchn (mean)IMFnn BA2TOT IMFon wbsal (mean)lntot infl wdi_gdpcapcon2010 wdi_gdppppcur KOFPoGI KOFFiGI peg growth_WDI p_ipolity fh_inv v2x_corr_VDEM sfi_SFI presany_DPI leftany_DPI exelec legelec s_unga3g7 coupi civwar_UCDP banks3 eventsNat natres lnpop F1, by(iso3)
  
  g treat1=defchn>0
  replace treat1=. if defchn==.
  g lngdppc=ln(wdi_gdpcapcon)
  g lngdp=ln(wdi_gdpppp)
  
  balancetable treat1 IMFnn BA2TOT lngdppc lngdp lntot infl growth natres eventsNat KOFFiGI p_ipolity presany leftany sfi KOFPoGI coupi banks3 civwar_UCDP v2x_corr_VDEM unsc_DSV s_unga using "Table A10.xlsx", replace wide(mean1 mean2 diff se)
  
  restore


* Table A10: China loans and IMF conditions by IMF facility  
  
  qui reghdfe BA2TOT l.lnchina l.lntot $M0 if sample==1 & IMFncc==1, a(cid year) cl(cid)
  est store r41
  qui reghdfe BA2TOT l.lnchina l.lntot $M1 if sample==1 & IMFncc==1, a(cid year) cl(cid)
  est store r42
  qui reghdfe BA2TOT l.lnchina l.lntot $M2 if sample==1 & IMFncc==1, a(cid year) cl(cid)
  est store r43
  qui reghdfe BA2TOT l.lnchina l.lntot $M0 if sample==1 & IMFcc==1, a(cid year) cl(cid)
  est store r44
  qui reghdfe BA2TOT l.lnchina l.lntot $M1 if sample==1 & IMFcc==1, a(cid year) cl(cid)
  est store r45
  qui reghdfe BA2TOT l.lnchina l.lntot $M2 if sample==1 & IMFcc==1, a(cid year) cl(cid)
  est store r46
  estout r4*, drop(_*) starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(N r2_a, fmt(0 3))   
  
 
* Table A11: Instrumental-variable design: China loans, domestic crisis, and IMF conditionality.
  
  egen m_china=mean(chinadebt), by(cid)
  g m_lnchina=ln(.1+m_china)
  g ivchn=m_lnchina*chn_steel
  qui xi:reg i.year i.cid
  
  qui capture:ivreg2 BA2TOT (l.lnchina=ivchn m_lnchina chn_ste) l.lntot $M0 ms5 _Icid* _Iyear* if IMFnn==1 & sample==1, first cl(cid)
  est store r51
  qui capture:ivreg2 BA2TOT (l.lnchina=ivchn m_lnchina chn_ste) l.lntot $M1 ms5 _Icid* _Iyear* if IMFnn==1 & sample==1, first cl(cid)
  est store r52
  qui capture:ivreg2 BA2TOT (l.lnchina=ivchn m_lnchina chn_ste) l.lntot $M2 ms5 _Icid* _Iyear* if IMFnn==1 & sample==1, first cl(cid)
  est store r53
  estout r5*, drop(_* ) starlevels(* .1 ** .05 *** .01) cells((b(star fmt(3)) se(par fmt(3)))) stats(N r2 idstat, fmt(0 3 3)) 

  
* Table A12: Outcomes of Chinese lending.

  qui reghdfe d.capform_WDI l.capform l.lnchina l.lntot $M0 if sample==1, a(cid year) vce(cl cid)
  est store r61
  qui reghdfe d.pcons l.pcons l.lnchina l.lntot $M0 if sample==1, a(cid year) vce(cl cid)
  est store r62
  qui reghdfe d.rtfp l.rtfp l.lnchina l.lntot $M0 if sample==1, a(cid year) vce(cl cid)
  est store r63
  qui reghdfe d.hf_finan l.hf_finan l.lnchina l.lntot $M0 if sample==1, a(cid year) vce(cl cid)
  est store r64
  qui reghdfe d.lninrs l.lninrs l.lnchina l.lntot $M0 if sample==1, a(cid year) vce(cl cid)
  est store r65
  qui reghdfe d.npl l.npl l.lnchina l.lntot $M0 if sample==1, a(cid year) vce(cl cid)
  est store r66
  estout r6*, drop(_*) starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(N r2_a, fmt(0 3))
  

* Table A13: Outcomes of Chinese lending using instrumental-variables analysis.

  mat G=J(3,6,0)
  qui cmp (EQ:d.capform=l.capform l.lnchina l.lntot $M0 _Iyear* _Icid*) (lnchina=ivchn l.lntot $M0 _Iyear* _Icid*) if sample==1, indicators(1 1) cl(cid) iterate(20)  
   est store r71
   qui test [lnchina]ivchn
   mat G[3,1]=r(chi2)
   mat G[1,1]=e(N1)
   qui xtreg d.capform l.capform l.lnchina l.lntot $M0 _Iyear*, fe 
   mat G[2,1]=e(r2_w)
  qui cmp (EQ:d.pcons=l.pcons l.lnchina l.lntot $M0 _Iyear* _Icid*) (lnchina=ivchn l.lntot $M0 _Iyear* _Icid*) if sample==1, indicators(1 1) cl(cid) iterate(20)  
   est store r72
   qui test [lnchina]ivchn
   mat G[3,2]=r(chi2)
   mat G[1,2]=e(N1)
   qui xtreg d.pcons l.pcons l.lnchina l.lntot $M0 _Iyear*, fe 
   mat G[2,2]=e(r2_w)
  qui cmp (EQ:d.rtfp=l.rtfp l.lnchina l.lntot $M0 _Iyear* _Icid*) (lnchina=ivchn l.lntot $M0 _Iyear* _Icid*) if sample==1, indicators(1 1) cl(cid) iterate(20)  
   est store r73
   qui test [lnchina]ivchn
   mat G[3,3]=r(chi2)
   mat G[1,3]=e(N1)
   qui xtreg d.rtfp l.rtfp l.lnchina l.lntot $M0 _Iyear*, fe 
   mat G[2,3]=e(r2_w)
  qui cmp (EQ:d.hf_financ=l.hf_financ l.lnchina l.lntot $M0 _Iyear* _Icid*) (lnchina=ivchn l.lntot $M0 _Iyear* _Icid*) if sample==1, indicators(1 1) cl(cid) iterate(20)  
   est store r74
   qui test [lnchina]ivchn
   mat G[3,4]=r(chi2)
   mat G[1,4]=e(N1)
   qui xtreg d.hf_fina l.hf_fina l.lnchina l.lntot $M0 _Iyear*, fe 
   mat G[2,4]=e(r2_w)
  qui cmp (EQ:d.lninrs=l.lninrs l.lnchina l.lntot $M0 _Iyear* _Icid*) (lnchina=ivchn l.lntot $M0 _Iyear* _Icid*) if sample==1, indicators(1 1) cl(cid) iterate(20)  
   est store r75
   qui test [lnchina]ivchn
   mat G[3,5]=r(chi2)
   mat G[1,5]=e(N1)
   qui xtreg d.lninrs l.lninrs l.lnchina l.lntot $M0 _Iyear*, fe 
   mat G[2,5]=e(r2_w)
  qui cmp (EQ:d.npl=l.npl l.lnchina l.lntot $M0 _Iyear* _Icid*) (lnchina=ivchn l.lntot $M0 _Iyear* _Icid*) if sample==1, indicators(1 1) cl(cid) iterate(20)  
   est store r76
   qui test [lnchina]ivchn
   mat G[3,6]=r(chi2)
   mat G[1,6]=e(N1)
   qui xtreg d.npl l.npl l.lnchina l.lntot $M0 _Iyear*, fe 
   mat G[2,6]=e(r2_w)
	
  estout r7*, drop(_* *year* *0* *ch*:) starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) 
  mat li G
	
    
* Diagnostics 

  qui xtreg IMFnn ms5 l.defany l.defchn $LX0 if sample==1, fe 
  est store hmfe
  qui xtreg IMFnn ms5 l.defany l.defchn $LX0 if sample==1, re 
  hausman hmfe ., sigmamore

  